// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import MintUI from 'mint-ui'
import store from './store/index.js'
import echarts from 'echarts'
// import "mint-ui/lib/style.css"
import "../static/css/style.css"
import "../static/css/animate.css"
import {fetch, post} from './utils/https'

Vue.prototype.$echarts = echarts
Vue.prototype.$fetch = fetch
Vue.prototype.$post = post

Vue.use(MintUI)

Vue.config.productionTip = false


/* 设置全局路由拦截规则 */
router.beforeEach((to, from, next) => {
  // console.log('全局路由控制');  //旧版本
  if (to.matched.some(route => route.meta.requireAuth)) {
    let token = getToken();//获取token
    if (token) {
      next();
    } else {
      next({
        path: '/login',
        query: {redirect: to.fullPath}
      })
    }
  } else {
    next();
  }
})


/* eslint-disable no-new */
if ("addEventListener" in document) {
  document.addEventListener("deviceready", function () {
    FastClick.attach(document.body);
    window.navigator.splashscreen.hide();
  }, false);
}

new Vue({
  el: "#app",
  router,
  store,
  template: "<App/>",
  components: {App}
});


function getToken() {
  return window.localStorage.getItem('token');
}
